CHAT ASN.1 X.509
Чат 💬 протокол Максима Сохацького в ASN.1 нотації
апробований в Гонконзі в 2017 розширений до промислового
X.509 варіанту для потреб електронного цифрового підпису КУПИНА
та симетричного блочного шифру КАЛИНА в стандартних
конвертах X.509, таких як CSR, CMS, LDAP, DNS, тощо.
Зміст
1) Чат протокол
2) Контакти
3) Записна книжка
4) Аунтентифікація та реєстрація
5) Повідомлення
6) Топіки та групи
7) Профілі та сервера
8) Передача файлів
9) Пошук по директорії
10) Френдування профілів
11) Налаштування
Чат протокол
CHAT DEFINITIONS IMPLICIT TAGS ::= BEGIN
CHATProtocol ::= CHOICE {
register [0] Register,
auth [1] Auth,
feature [2] Feature,
service [3] Service,
message [4] Message,
profile [5] Profile,
room [6] Room,
member [7] Member,
search [8] Search,
file [9] FileDesc,
typing [10] Typing,
friend [11] Friend,
presence [12] Presence,
history [13] History,
roster [14] Roster }
CHATMessage ::= SEQUENCE {
no INTEGER,
headers SEQUENCE OF header OCTET STRING,
body CHATProtocol }
IO ::= SEQUENCE { data UniversalString, code UniversalString }
OK ::= SEQUENCE { data UniversalString }
ERROR ::= SEQUENCE { code UniversalString }
P2P ::= SEQUENCE { from OCTET STRING, to OCTET STRING }
MUC ::= SEQUENCE { room OCTET STRING }
Контакти
ContactStatus ::= ENUMERATED {
request (1),
authorization (2),
ignore (3),
internal (4),
friend (5),
lastmsg (6),
ban (7),
banned (8),
deleted (9),
nonexised (10) }
Contact ::= SEQUENCE {
nickname OCTET STRING,
avatar OCTET STRING,
names SEQUENCE OF name OCTET STRING,
phone OCTET STRING,
surnames SEQUENCE OF name OCTET STRING,
lastmsg Message,
presence PresenceType,
update INTEGER,
created INTEGER,
settings SEQUENCE OF feature Feature,
services SEQUENCE OF service Service,
status ContactStatus }
Записна книжка
RosterStatus ::= ENUMERATED {
get (1), create (2), del (3), remove (4), nick (5), search (6),
contact (7), add (8), update (9), list (10), patch (11), lastmsg (12) }
Roster ::= SEQUENCE {
id OCTET STRING,
nickname OCTET STRING,
update INTEGER,
contacts SEQUENCE OF contact Contact,
topics SEQUENCE OF room Room,
status RosterStatus }
Аутентифікація та реєстрація
Auth ::= SEQUENCE {
session OCTET STRING,
type AuthType,
cert OCTET STRING,
challange OCTET STRING,
push OCTET STRING,
os OS,
nickname OCTET STRING,
settings SEQUENCE OF feature Feature,
token OCTET STRING,
devkey OCTET STRING,
phone OCTET STRING }
Повідомлення
Ack ::= SEQUENCE { table OCTET STRING, id OCTET STRING }
MessageType ::= ENUMERATED { sys (1),
reply (2), forward (3), read (4), edited (5) }
MessageStatus ::= ENUMERATED { async (1), delete (2),
clear (3), update (4), edit (5) }
MessageFeed ::= CHOICE { p2p [0] P2P, muc [1] MUC }
CHATString ::= OCTET STRING
Message ::= SEQUENCE {
id CHATString,
feed MessageFeed,
signature CHATString,
from CHATString,
to CHATString,
created INTEGER,
files SEQUENCE OF file FileDesc,
type MessageType,
link CHOICE { empty [1] NULL, message [2] Message },
seenby CHATString,
repliedby CHATString,
mentioned SEQUENCE OF name CHATString,
status MessageStatus DEFAULT clear }
Топіки та групи
MemberStatus ::= ENUMERATED { admin (1),
member (2), removed (3), patch (4), owner (5) }
Member ::= SEQUENCE {
id INTEGER,
feed CHOICE { p2p [0] P2P, muc [1] MUC },
feeds SEQUENCE OF feed OCTET STRING,
phone OCTET STRING,
avatar OCTET STRING,
names SEQUENCE OF name OCTET STRING,
surnames SEQUENCE OF name OCTET STRING,
alias OCTET STRING,
update INTEGER,
settings SEQUENCE OF feature Feature,
services SEQUENCE OF servic Service,
presence PresenceType,
status MemberStatus }
RoomType ::= ENUMERATED { group (1), channel (2), call (3) }
RoomStatus ::= ENUMERATED {
create (1), leave (2), add (3), remove (4), removed (5),
join (6), joined (7), info (8), patch (9), get (10),
delete (11), lastmsg (12), mute (13), unmute (14) }
Room ::= SEQUENCE {
id OCTET STRING,
name OCTET STRING,
links SEQUENCE OF link OCTET STRING,
description OCTET STRING,
settings SEQUENCE OF feature Feature,
members SEQUENCE OF member Member,
admins SEQUENCE OF member Member,
data SEQUENCE OF file FileDesc,
type RoomType,
tos OCTET STRING,
tosupdate INTEGER,
unread INTEGER,
mentions SEQUENCE OF contact INTEGER,
lastmsg Message,
update INTEGER,
created INTEGER,
status RoomStatus }
Профілі на серверах
Server ::= SEQUENCE { service OCTET STRING, port INTEGER, host OCTET STRING }
OS ::= ENUMERATED { apple (1), microsoft (2), google (3), ericsson (4) }
AuthType ::= ENUMERATED { reg (1), auth (2), forget (3), renew (4) }
Profile ::= SEQUENCE {
nickname OCTET STRING,
phone OCTET STRING,
session OCTET STRING,
chats SEQUENCE OF contact Contact,
contacts SEQUENCE OF contact Contact,
keys SEQUENCE OF key OCTET STRING,
servers SEQUENCE OF server Server,
settings SEQUENCE OF feature Feature,
update INTEGER,
status INTEGER,
roster Roster }
Передача файлів
FileDesc ::= SEQUENCE {
id OCTET STRING,
mime OCTET STRING,
payload ANY,
parentid OCTET STRING,
data SEQUENCE OF feature Feature }
Пошук по директорії
SearchStatus ::= ENUMERATED { ok (0) }
Criteria ::= ENUMERATED {
equal (0), notequal (1), like (2) }
Scope ::= ENUMERATED {
profile (0), folder (1), contact (2),
member (3), room (4), chat (5), message (6) }
Search ::= SEQUENCE {
dn OCTET STRING,
id OCTET STRING,
field OCTET STRING,
value OCTET STRING,
criteria Criteria,
type Scope,
status SearchStatus }
Typing ::= SEQUENCE {
session OCTET STRING,
nickname OCTET STRING,
comments SEQUENCE OF comment OCTET STRING }
Френдування профілів
Friendship ::= ENUMERATED {
request (1), confirm (2), update (3), ignore (4),
ban (5), unban (6) }
Friend ::= SEQUENCE {
nickname OCTET STRING,
friend OCTET STRING,
type Friendship }
Історія чату
HistoryStatus ::= ENUMERATED {
updated (1), get (2), update (3), lastloaded (4),
lastmsg (5), getreply (6), doubleget (7),
delete (8), image (9), video (10), file (11),
link (12), audio (13), contact (14), location (15), text (16) }
History ::= SEQUENCE {
nickname OCTET STRING,
feed CHOICE { p2p [0] P2P, muc [1] MUC },
size INTEGER,
entity INTEGER,
data SEQUENCE OF message Message,
roster UniversalString,
status HistoryStatus }
Налаштування
Feature ::= SEQUENCE {
id OCTET STRING,
key OCTET STRING,
value OCTET STRING,
group OCTET STRING }
ServiceType ::= ENUMERATED {
synrc (0),
aws (1),
gcp (2),
azure (3) }
ServiceStatus ::= ENUMERATED {
verified (0),
added (1),
add (2),
remove (3) }
Service ::= SEQUENCE {
id OCTET STRING,
type ServiceType,
data OCTET STRING,
login OCTET STRING,
password OCTET STRING,
expiration INTEGER,
status ServiceStatus }
Register ::= SEQUENCE {
nickname OCTET STRING,
csr OCTET STRING,
password OCTET STRING }
PresenceType ::= ENUMERATED { offline (1), online (2) }
Presence ::= SEQUENCE { nickname OCTET STRING, status PresenceType }
END
Висновки
Якшо не модифікувати протокол, то ASN.1/BER в 2-3 рази (в залежності від zlib компресії BERT)
ефективніший BERT/ETF, який у свою чергу ефективніший
ніж JSON. ASN.1 протокол використовується для КЕП,
LDAP, DNS, X.509 PKI, CSR, PKCS, TLS, CMS,
тому природнім чином визначати телекомунікаційні
протоколи в ASN.1.
ASN.1/BER
> {:ok, asn1} = :CHAT.encode(:CHATMessage, CHAT."CHATMessage"(no: 1,
headers: [], body: {:message,CHAT."Message"(id: "5HT", feed: {:muc,
CHAT."MUC"(room: "1")}, signature: "", from: "sys", to: "5HT", created: 1,
files: [], type: :sys, link: {:empty,"NULL"}, seenby: "", repliedby: "",
mentioned: [])}))
{:ok,
<<48, 45, 2, 1, 1, 48, 0, 164, 38, 4, 3, 53, 72, 84, 161, 3, 4, 1, 49, 4, 0, 4,
3, 115, 121, 115, 4, 3, 53, 72, 84, 2, 1, 1, 48, 0, 10, 1, 1, 129, 0, 4, 0,
4, 0, 48, 0>>}
> :erlang.size asn1
47
ETF/BERT
> bert = :erlang.term_to_binary CHAT."CHATMessage"(no: 1,
headers: [], body: {:message,CHAT."Message"(id: "5HT", feed: {:muc,
CHAT."MUC"(room: "1")}, signature: "", from: "sys", to: "5HT", created: 1,
files: [], type: :sys, link: {:empty,"NULL"}, seenby: "", repliedby: "",
mentioned: [])}), [:compressed]
<<131, 80, 0, 0, 0, 140, 120, 156, 203, 96, 41, 231, 118, 246, 112, 12, 241, 77,
45, 46, 78, 76, 79, 77, 100, 204, 202, 96, 42, 103, 207, 133, 240, 50, 248,
202, 217, 161, 18, 185, 12, 12, 12, 204, 166, 30, 33, 64, 89, 230, ...>>
> :erlang.size bert
114
˙
˙
[1]. CHAT ASN.1 SPECIFICATION